using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class OCEEditCodeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public OCEEditCodeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.User;
						tableVersionTypes[HL7Version.v251] = HL7TableType.User;
						tableVersionTypes[HL7Version.v26] = HL7TableType.User;
						tableVersionTypes[HL7Version.v27] = HL7TableType.User;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v24] = new string[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40.","41.","42.","..."};
						validVersionCodes[HL7Version.v25] = new string[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40.","41.","42."};
						validVersionCodes[HL7Version.v251] = new string[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40.","41.","42."};
						validVersionCodes[HL7Version.v26] = new string[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40.","41.","42.","..."};
						validVersionCodes[HL7Version.v27] = new string[]{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35.","36.","37","38.","39.","40.","41.","42.","..."};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v24] = new string[]{"Invalid diagnosis code","Diagnosis and age conflict","Diagnosis and sex conflict","Medicare secondary payer alert","E-code as reason for visit","Invalid procedure code","Procedure and age conflict","Procedure and sex conflict","Nov-covered service","Non-covered  service submitted for verification of denial (condition code 21 from header information on claim)","Non-covered service submitted for FI review (condition code 20 from header information on claim)","Questionable covered service","Additional payment for service not provided by Medicare","Code indicates a site of service not included in OPPS","Service unit out of range for procedure","Multiple bilateral procedures without modifier 50 (see Appendix A)","Multiple bilateral procedures with modifier 50 (see Appendix A)","Inpatient procedure","Mutually exclusive procedure that is not allowed even if appropriate modifier present","Component of a comprehensive procedure that is not allowed even if appropriate modifier present","Medical visit on same day as a type \"T\" or \"S\" procedure without modifier 25 (see Appendix B)","Invalid modifier","Invalid date","Date out of OCE range","Invalid age","Invalid sex","Only incidental services reported","Code not recognized by Medicare; alternate code for same service available","Partial hospitalization service for non-mental health diagnosis","Insufficient services on day of partial hospitalization","Partial hospitalization on same day as ECT or type \"T\" procedure","Partial hospitalization claim spans 3 or less days with in-sufficient services, or ECT or significant procedure on at least one of the days","Partial hospitalization claim spans more than 3 days with insufficient number of days having mental health services","Partial hospitalization claim spans more than 3 days with insufficient number of days meeting partial hospitalization criteria","Only activity therapy and/or occupational therapy services provided","Extensive mental health services provided on day of ECT or significant procedure","Terminated bilateral procedure or terminated procedure with units greater than one","Inconsistency between implanted device and implantation procedure","Mutually exclusive procedure that would be allowed if appropriate modifier were present","Component of a comprehensive procedure that would be allowed if appropriate modifier were present","Invalid revenue code","Multiple medical visits on same day with same revenue code without condition code G0 (see Appendix B)",""};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Invalid diagnosis code","Diagnosis and age conflict","Diagnosis and sex conflict","Medicare secondary payer alert","E-code as reason for visit","Invalid procedure code","Procedure and age conflict","Procedure and sex conflict","Nov-covered service","Non-covered  service submitted for verification of denial (condition code 21 from header information on claim)","Non-covered service submitted for FI review (condition code 20 from header information on claim)","Questionable covered service","Additional payment for service not provided by Medicare","Code indicates a site of service not included in OPPS","Service unit out of range for procedure","Multiple bilateral procedures without modifier 50 (see Appendix A)","Multiple bilateral procedures with modifier 50 (see Appendix A)","Inpatient procedure","Mutually exclusive procedure that is not allowed even if appropriate modifier present","Component of a comprehensive procedure that is not allowed even if appropriate modifier present","Medical visit on same day as a type \"T\" or \"S\" procedure without modifier 25 (see Appendix B)","Invalid modifier","Invalid date","Date out of OCE range","Invalid age","Invalid sex","Only incidental services reported","Code not recognized by Medicare; alternate code for same service available","Partial hospitalization service for non-mental health diagnosis","Insufficient services on day of partial hospitalization","Partial hospitalization on same day as ECT or type \"T\" procedure","Partial hospitalization claim spans 3 or less days with in-sufficient services, or ECT or significant procedure on at least one of the days","Partial hospitalization claim spans more than 3 days with insufficient number of days having mental health services","Partial hospitalization claim spans more than 3 days with insufficient number of days meeting partial hospitalization criteria","Only activity therapy and/or occupational therapy services provided","Extensive mental health services provided on day of ECT or significant procedure","Terminated bilateral procedure or terminated procedure with units greater than one","Inconsistency between implanted device and implantation procedure","Mutually exclusive procedure that would be allowed if appropriate modifier were present","Component of a comprehensive procedure that would be allowed if appropriate modifier were present","Invalid revenue code","Multiple medical visits on same day with same revenue code without condition code G0 (see Appendix B)"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Invalid diagnosis code","Diagnosis and age conflict","Diagnosis and sex conflict","Medicare secondary payer alert","E-code as reason for visit","Invalid procedure code","Procedure and age conflict","Procedure and sex conflict","Nov-covered service","Non-covered  service submitted for verification of denial (condition code 21 from header information on claim)","Non-covered service submitted for FI review (condition code 20 from header information on claim)","Questionable covered service","Additional payment for service not provided by Medicare","Code indicates a site of service not included in OPPS","Service unit out of range for procedure","Multiple bilateral procedures without modifier 50 (see Appendix A)","Multiple bilateral procedures with modifier 50 (see Appendix A)","Inpatient procedure","Mutually exclusive procedure that is not allowed even if appropriate modifier present","Component of a comprehensive procedure that is not allowed even if appropriate modifier present","Medical visit on same day as a type \"T\" or \"S\" procedure without modifier 25 (see Appendix B)","Invalid modifier","Invalid date","Date out of OCE range","Invalid age","Invalid sex","Only incidental services reported","Code not recognized by Medicare; alternate code for same service available","Partial hospitalization service for non-mental health diagnosis","Insufficient services on day of partial hospitalization","Partial hospitalization on same day as ECT or type \"T\" procedure","Partial hospitalization claim spans 3 or less days with in-sufficient services, or ECT or significant procedure on at least one of the days","Partial hospitalization claim spans more than 3 days with insufficient number of days having mental health services","Partial hospitalization claim spans more than 3 days with insufficient number of days meeting partial hospitalization criteria","Only activity therapy and/or occupational therapy services provided","Extensive mental health services provided on day of ECT or significant procedure","Terminated bilateral procedure or terminated procedure with units greater than one","Inconsistency between implanted device and implantation procedure","Mutually exclusive procedure that would be allowed if appropriate modifier were present","Component of a comprehensive procedure that would be allowed if appropriate modifier were present","Invalid revenue code","Multiple medical visits on same day with same revenue code without condition code G0 (see Appendix B)"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Invalid diagnosis code","Diagnosis and age conflict","Diagnosis and sex conflict","Medicare secondary payer alert","E-code as reason for visit","Invalid procedure code","Procedure and age conflict","Procedure and sex conflict","Nov-covered service","Non-covered  service submitted for verification of denial (condition code 21 from header information on claim)","Non-covered service submitted for FI review (condition code 20 from header information on claim)","Questionable covered service","Additional payment for service not provided by Medicare","Code indicates a site of service not included in OPPS","Service unit out of range for procedure","Multiple bilateral procedures without modifier 50 (see Appendix A)","Multiple bilateral procedures with modifier 50 (see Appendix A)","Inpatient procedure","Mutually exclusive procedure that is not allowed even if appropriate modifier present","Component of a comprehensive procedure that is not allowed even if appropriate modifier present","Medical visit on same day as a type \"T\" or \"S\" procedure without modifier 25 (see Appendix B)","Invalid modifier","Invalid date","Date out of OCE range","Invalid age","Invalid sex","Only incidental services reported","Code not recognized by Medicare; alternate code for same service available","Partial hospitalization service for non-mental health diagnosis","Insufficient services on day of partial hospitalization","Partial hospitalization on same day as ECT or type \"T\" procedure","Partial hospitalization claim spans 3 or less days with in-sufficient services, or ECT or significant procedure on at least one of the days","Partial hospitalization claim spans more than 3 days with insufficient number of days having mental health services","Partial hospitalization claim spans more than 3 days with insufficient number of days meeting partial hospitalization criteria","Only activity therapy and/or occupational therapy services provided","Extensive mental health services provided on day of ECT or significant procedure","Terminated bilateral procedure or terminated procedure with units greater than one","Inconsistency between implanted device and implantation procedure","Mutually exclusive procedure that would be allowed if appropriate modifier were present","Component of a comprehensive procedure that would be allowed if appropriate modifier were present","Invalid revenue code","Multiple medical visits on same day with same revenue code without condition code G0 (see Appendix B)",""};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Invalid diagnosis code","Diagnosis and age conflict","Diagnosis and sex conflict","Medicare secondary payer alert","E-code as reason for visit","Invalid procedure code","Procedure and age conflict","Procedure and sex conflict","Nov-covered service","Non-covered  service submitted for verification of denial (condition code 21 from header information on claim)","Non-covered service submitted for FI review (condition code 20 from header information on claim)","Questionable covered service","Additional payment for service not provided by Medicare","Code indicates a site of service not included in OPPS","Service unit out of range for procedure","Multiple bilateral procedures without modifier 50 (see Appendix A)","Multiple bilateral procedures with modifier 50 (see Appendix A)","Inpatient procedure","Mutually exclusive procedure that is not allowed even if appropriate modifier present","Component of a comprehensive procedure that is not allowed even if appropriate modifier present","Medical visit on same day as a type \"T\" or \"S\" procedure without modifier 25 (see Appendix B)","Invalid modifier","Invalid date","Date out of OCE range","Invalid age","Invalid sex","Only incidental services reported","Code not recognized by Medicare; alternate code for same service available","Partial hospitalization service for non-mental health diagnosis","Insufficient services on day of partial hospitalization","Partial hospitalization on same day as ECT or type \"T\" procedure","Partial hospitalization claim spans 3 or less days with in-sufficient services, or ECT or significant procedure on at least one of the days","Partial hospitalization claim spans more than 3 days with insufficient number of days having mental health services","Partial hospitalization claim spans more than 3 days with insufficient number of days meeting partial hospitalization criteria","Only activity therapy and/or occupational therapy services provided","Extensive mental health services provided on day of ECT or significant procedure","Terminated bilateral procedure or terminated procedure with units greater than one","Inconsistency between implanted device and implantation procedure","Mutually exclusive procedure that would be allowed if appropriate modifier were present","Component of a comprehensive procedure that would be allowed if appropriate modifier were present","Invalid revenue code","Multiple medical visits on same day with same revenue code without condition code G0 (see Appendix B)",""};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
